package com.yckj.day05;

import java.util.Arrays;
import java.util.Random;

public class DoubleBallLottery {
	public static void main(String[] args) {
		System.out.println("生成双色球号码："+ Arrays.toString(gen()));

	}
	/**
	 * 生成双色球的方法
	 * @return
	 * @return String[]
	 */
	public static String[] gen() {
		String[] pool = {"01","02","03","04","05","06","07","08","09","10","11",
				         "12","13","14","15","16","17","18","19","20","21","22",
				         "23","24","25","26","27","28","29","30","31","32","33"};
		boolean[] used = new boolean[pool.length];//使用标记,used数组里的元素默认值为false
		Random r  = new Random();
		String[] balls = new String[6];//创建一个数组用于存储选出来的红球
		int i = 0;//声明balls数组的下标
		while(true) {
			int index = r.nextInt(pool.length);//生成随机下标
			if(used[index]) {//检查下标是否使用过
				continue;//如果使用过，重新执行循环，继续生成随机下标				
			}
			balls[i] = pool[index];//取出一个球到balls数组里
			i = i + 1;
			used[index] = true;//标识使用过了
			if(i == balls.length) {//检查是否都取满了
				break;//如果取满了跳出循环
			}			
		}
		Arrays.sort(balls);//对红球排序
		balls = Arrays.copyOf(balls, balls.length+1);//复制一个比balls长度多一个位置的数组，给蓝球留位置
		balls[balls.length - 1] = pool[r.nextInt(16)];//求出蓝球
		return balls;
	}
	

}
